# coding: utf-8

class Ambiguous
	def x; 1; end # A method named "x". Always returns 1
	def test
		puts x # No variable has been seen; refers to method above: prints 1
		# The line below is never evaluated, because of the "if false" clause. But
		# the parser sees it and treats x as a variable for the rest of the method.
		x = 0 if false
		puts x # x is a variable, but has never been assigned to: prints nil
		x = 2 # This assignment does get evaluated
		puts x # So now this line prints 2
	end
end

a = Ambiguous.new
a.test

# 并行赋值

# Same number of lvalues and rvalues
x, y, z = 1, 2, 3
puts x, y, z

# One lvalue, multiple rvalues
x = 1, 2, 3
puts x

*x = 1, 2, 3
puts x

x, = 1, 2, 3
puts x

# Multiple lvalues, single array rvalue
x, y, z = [1, 2, 3]
puts x, y, z

x, = [1,2]
puts x

# Different numbers of lvalues and rvalues
x, y, z = 1, 2
puts x, y, z

x, y, z = 1, 2, 3, 4
puts x, y, z

# The splat operator
x, y, z = 1, *[2, 3]
puts x, y, z

x, *y = 1, 2, 3
puts x, y

x, y, *z = 1, *[2,3,4] # x=1; y=2; z=[3,4]

puts x, y, z

# Parentheses in parallel assignment
a, (b, (c, d)) = [1, [2, [3, 4]]]
puts a, b, c, d

puts((x,y=1,2))